﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VLUSM_DataAccess.Repositories
{
    public class DVHCCap1Repository : GenericRepository<DonViHanhChinhContainer>
    {
        public DVHCCap1Repository(string connectionString) : base(connectionString, "DonViHanhChinh") { }
        public DVHCCap1Repository(DonViHanhChinhContainer context) : base(context) { }

        public DVHCCap1 GetSingleByID(int IDFilter)
        {
            var query = this.GetFirst<DVHCCap1>(d => d.ID == IDFilter);
            return query;
        }

        public DVHCCap1 GetSingleByTen(string TenFilter)
        {
            var query = this.GetFirst<DVHCCap1>(d => d.Ten == TenFilter);
            return query;
        }

        public DVHCCap1 GetSingleByMaDonVi(string MaDonViFilter)
        {
            var query = this.GetFirst<DVHCCap1>(d => d.MaDonVi == MaDonViFilter);
            return query;
        }

        public IEnumerable<DVHCCap1> GetAll()
        {
            var query = this.GetAll<DVHCCap1>();
            return query;
        }

        public void Save(DVHCCap1 obj)
        {
            try
            {
                if (obj.ID != 0)
                {
                    this.Attach<DVHCCap1>(obj);
                }
                else
                {
                    this.Add<DVHCCap1>(obj);
                }
            }
            catch { }
        }

        public void Remove(DVHCCap1 obj)
        {
            this.Delete<DVHCCap1>(obj);
        }

        public void Remove(int IDFilter)
        {
            var obj = this.GetSingleOrDefault<DVHCCap1>(d => d.ID == IDFilter);
            this.Delete<DVHCCap1>(obj);
        }
    }
}
